/**
 *
 */
package br.com.puertorico.model.querybuilder.wrappers;

import br.com.puertorico.model.querybuilder.annotations.WhereClause;

/**
 * @author daniel
 * @version 1.0.0
 */
public class WhereClauseWrapper implements GraphElement, Comparable<WhereClauseWrapper> {

	private String id;

	private WhereClause whereClause;

	private Integer order;

	/**
	 * @param whereClause
	 * @param order
	 */
	public WhereClauseWrapper(WhereClause whereClause, Integer order) {
		id = whereClause.id();
		this.whereClause = whereClause;
		this.order = order;
	}

	/**
	 * @return the whereClause
	 */
	public String getWhereClause() {
		StringBuilder hql = new StringBuilder();
		hql.append(whereClause.value());
		return hql.toString();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * br.ufms.nin.jpa.querybuilder.wrapper.GraphElement#getDependencies()
	 */
	public String[] getDependencies() {
		return whereClause.dependsOn();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * br.ufms.nin.jpa.querybuilder.wrapper.GraphElement#getElementId()
	 */
	public String getElementId() {
		return whereClause.id();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof WhereClauseWrapper) {
			return ((WhereClauseWrapper) obj).id.equals(id);
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return id.hashCode();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	public int compareTo(WhereClauseWrapper o) {
		return o.order.compareTo(order);
	}
}
